#include <QCoreApplication>

#include <stdio.h>

#include <lcm/lcm-cpp.hpp>
#include "DataType.hpp"

class Handle{
public:
    ~Handle(){}

    void handleMsg(const lcm::ReceiveBuffer *rBuf, const std::string &channel,
                   const exlcm::DataType *msg){
        int i;
        printf("Recv msg on chan \"%s\":\n", channel.c_str());
        printf(" timeStamp = %lld\n", (long long)msg->timestamp);
        printf(" position = (%f, %f, %f)\n", msg->position[0], msg->position[1],
                msg->position[2]);
        printf(" orientation = (%f, %f, %f, %f)", msg->orientation[0],
                msg->orientation[1], msg->orientation[2], msg->orientation[3]);
        printf(" ranges:");
        for (i=0;i<msg->num_ranges;i++) {
            printf(" %d",msg->ranges[i]);
        }
        printf("\n");
        printf(" name = %s\n", msg->name.c_str());
        printf(" enable = %d\n", msg->enabled);
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    lcm::LCM lcm;
    if(!lcm.good()){
        return 1;
    }
    Handle handlerObject;
    lcm.subscribe("EXAMPLE", &Handle::handleMsg, &handlerObject);

    while (0 == lcm.handle()) {

    }
    return a.exec();
}
